<template>
	<view>
		<!-- 顶部导航 -->
		<fa-navbar title="会员资料" ref="navbar" ></fa-navbar>
		<view class="content">
			<u-form :model="form" ref="uForm">
				<u-form-item label="姓名" prop="name" label-width="140">
					<u-input v-model="form.name" />
				</u-form-item>
				<u-form-item label="手机号" prop="mobile" label-width="140">
					<u-input v-model="form.mobile" />
				</u-form-item>
				<u-form-item label="年龄" prop="nl" label-width="140">
					<u-input v-model="form.nl" />
				</u-form-item>
				<u-form-item label="居住区域" prop="jzqy" label-width="140">
					<u-input v-model="form.jzqy" />
				</u-form-item>
				<u-form-item label="退休工资" prop="txgz" label-width="140">
					<u-input v-model="form.txgz" />
				</u-form-item>
				<u-form-item label="居住情况" prop="jzqk" label-width="140">
					<u-input v-model="form.jzqk" />
				</u-form-item>
				<u-form-item label="级别"  label-width="100">
					<u-input v-model="form.level_name" disabled="disabled"/>
				</u-form-item>
				<u-form-item label="推荐人" prop="tjr" label-width="140">
					<u-input v-model="form.tjr" disabled="disabled"/>
				</u-form-item>
				<u-form-item label="备注" prop="bz" label-width="140">
					<u-input v-model="form.bz" />
				</u-form-item>
				<u-form-item label="羊奶剩余" prop="yangnai" label-width="140">
					<u-input v-model="form.yangnai" />
				</u-form-item>
				<u-form-item label="沙棘剩余" prop="shaji" label-width="140">
					<u-input v-model="form.shaji" />
				</u-form-item>
				<u-form-item label="硒剩余" prop="xi" label-width="140">
					<u-input v-model="form.xi" />
				</u-form-item>
				<u-form-item label="黄精剩余" prop="huangjing" label-width="140">
					<u-input v-model="form.huangjing" />
				</u-form-item>
				<!-- <u-form-item label="性别" prop="sex" label-width="100">
					<u-radio-group v-model="value" @change="radioGroupChange">
						<u-radio 
							v-for="(item, index) in sexlist" :key="index" 
							:name="item.name"
							:disabled="item.disabled"
						>
							{{item.name}}
						</u-radio>
					</u-radio-group>
				</u-form-item> -->
				
			</u-form>
			<u-button @click="submit" :custom-style="customStyle">修改</u-button>
		</view>
		
		<!-- 底部导航 -->
		<fa-tabbar></fa-tabbar>
	</view>
</template>

<script>
	import { archives } from '@/common/fa.mixin.js';
	export default {
		mixins: [archives],
		onLoad(e) {
			let query = e || {};
			this.user_id = query.user_id || 0;
			this.is_update = true;
			this.memberDetail();
		},
		data() {
			return {
				user_id: 0,
				customStyle: {
					marginTop: '50px', // 注意驼峰命名，并且值必须用引号包括，因为这是对象
					color: '#333',
					border: 'none',
					background: '#e0ebdd',
				},
				sexlist: [
					{
						name: '男',
						disabled: false
					},
					{
						name: '女',
						disabled: false
					}
				],
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
				value: '男',
				form: {
					name: '',
					mobile: '',
					jzqy: '',
					txgz: '',
					jzqk: '',
					bz: '',
					nl: '',
					yangnai: '',
					shaji: '',
					xi: '',
					huangjing: '',
				},
				gl_name:'',
				rules: {
					name: [
						{ 
							required: true, 
							message: '请输入姓名', 
							// 可以单个或者同时写两个触发验证方式 
							trigger: ['change','blur'],
						}
					],
					mobile: [
						{
							required: true, 
							message: '请输入手机号',
							trigger: ['change','blur'],
						},
						{
							// 自定义验证函数，见上说明
							validator: (rule, value, callback) => {
								// 上面有说，返回true表示校验通过，返回false表示不通过
								// this.$u.test.mobile()就是返回true或者false的
								return this.$u.test.mobile(value);
							},
							message: '手机号码不正确',
							// 触发器可以同时用blur和change
							trigger: ['change','blur'],
						}
					]
				}
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			memberDetail: async function() {
				let data = {
					user_id: this.user_id 
				};
				
				let res = await this.$api.memberDetail(data);
				console.log(res,'11')
				this.form = res.data;
				this.form.name = res.data.username;
			},
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						console.log('验证通过',this.form);
						
						this.$api.editStoreMember({ 
							user_id:this.user_id,
							name: this.form.name,
							mobile: this.form.mobile,
							jzqy: this.form.jzqy,
							txgz: this.form.txgz,
							jzqk: this.form.jzqk,
							bz: this.form.bz,
							nl: this.form.nl,
							yangnai: this.form.yangnai,
							shaji: this.form.shaji,
							xi: this.form.xi,
							huangjing: this.form.huangjing,
						}).then(res => {
			
							if(res.code == 1){
								uni.showToast({
									title: '修改成功',
									icon: 'success',
									duration: 2000,
									success: function (res1) {
										setTimeout(() => {
											uni.redirectTo({
												url: '/pages/my/user_list'
											});
										}, 2000);
										
										
									},
								});
			
							}
							
						});
						
					} else {
						console.log('验证失败');
					}
				});
			},
			confirm(e) {
				this.form.gl_id = e[0].value;
				this.gl_name = e[0].label;
			},

			//性别
			radioGroupChange(e) {
				console.log(e,'22');
			}
		}
	};
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}
</style>
<style lang="scss" scoped>
	.content{
		width: 90%;margin: 10px auto;padding-bottom: 50px;
	}
</style>
